package model;

import main.GameCanvas;

import javax.microedition.lcdui.Graphics;

import screen.PaintPopup;
import utilities.GameResource;

import font.BitmapFont;

public class Item extends MyObj {
	public static final int ITEM_TYPE_ANIMAL		=  0;
	public static final int ITEM_TYPE_FOOD 			=  1;
	public static final int ITEM_TYPE_DRUG 			=  2;
	public static final int ITEM_TYPE_TOY 			=  3;
	public static final int ITEM_TYPE_AVATAR		=  4;
    

	public boolean m_bIsFocus = false;
	public int m_iNumItem;
	public byte m_bItemType;
	
	public ItemInfo itemInfo;
	
	public void paint(Graphics g) {
		// TODO Auto-generated method stub
		
	}

	public void paintIcon(Graphics g, int x, int y) {
		// TODO Auto-generated method stub
		itemInfo.paintIcon(g, x, y);
	}

	//paint in list
	public void paintInRow(Graphics g, int x, int y, int width, int height, boolean isFocus) {
		// TODO Auto-generated method stub
		String arr[] = BitmapFont.m_bmFont.splitFontBStrInLine(m_strName, width - 4);
		int tmpY = y + (height >> 1);
		if(arr.length >= 2){
			tmpY -= 7;

			int a = arr.length;
			for(int i = 0; i < a; i++){
				BitmapFont.drawBoldFont(g, arr[i], x + 2, tmpY, 0x3a001e, Graphics.VCENTER | Graphics.LEFT);
				
				tmpY += 15;
			}
		}
		else		
			BitmapFont.drawBoldFont(g, m_strName, x + 2, tmpY, 0x3a001e, Graphics.VCENTER | Graphics.LEFT);
	}

	//paint popup description in shop
	public void paintInfo(Graphics g, int x, int y) {
		// TODO Auto-generated method stub
		int widthBox = (BitmapFont.m_bmFont.stringWidth(m_strName) > 120)?(BitmapFont.m_bmFont.stringWidth(m_strName)+5):120;
		int heightBox = 40;
		
		boolean flag = false;
		//select the best position for popup
		if(y + heightBox > GameCanvas.h - 20){
			y -= (y + heightBox - (GameCanvas.h - 20));
			x = x + 32;
			flag = true;
		}
		if(x + widthBox > GameCanvas.w){
			x -= (x + widthBox - GameCanvas.w);
			if(flag)
				x -= 32;
		}
				
		//paint bouding
		PaintPopup.paintRoundRect(g, x, y, widthBox, heightBox, 0xffe783);
		y += 5;
		BitmapFont.drawBoldFont(g, m_strName, x + widthBox/2, y, 0x3a001e, Graphics.HCENTER | Graphics.HCENTER);
		
		y += 15;
        BitmapFont.drawNormalFont(g, GameResource.number + GameResource.space + m_iNumItem, 5 + x, y, 0x3a001e, Graphics.LEFT);			
 	}

	
	public MyObj clone() {
		// TODO Auto-generated method stub
		Item item = new Item();
		
		item.m_bItemType = this.m_bItemType;
		item.m_iId = this.m_iId;
		item.m_iNumItem = this.m_iNumItem;
		item.m_strName = this.m_strName;
		
		return item;
	}
	
}
